﻿using Electric.API.UOW;
using Eletric.API.AuditLog;
using Eletric.API.Exception;
using Eletric.API.UOW;

namespace Eletric.API.Extension
{
    /// <summary>
    /// Mvc相关扩展
    /// </summary>
    public static class MVCExtension
    {
        public static void AddExtensionControllers(this WebApplicationBuilder builder)
        {
            builder.Services.AddControllers(cofigure =>
            {
                //异常过滤器
                cofigure.Filters.Add<ElectricExceptionFilterAttribute>();
                //全局事务
                cofigure.Filters.Add<UnitOfWorkFilterAttribute>(); //全局事务关闭([UnitOfWork(IsTransactional = true)])
                //全局记录日志
                cofigure.Filters.Add<EletricActionFilterAttribute>();
            })
               .AddNewtonsoftJson(option =>
               {
                   option.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
               });
        }
    }
}